package Eyjafjalla.monster;

import Eyjafjalla.card.status.Burn_Eyjafjalla;
import Eyjafjalla.power.GiveRedCloudPower;
import Eyjafjalla.power.WhiteCloudPower;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.*;
import com.megacrit.cardcrawl.actions.unique.ApplyStasisAction;
import com.megacrit.cardcrawl.actions.utility.WaitAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.MonsterStrings;
import com.megacrit.cardcrawl.powers.StrengthPower;

public class CXXSS extends AbstractEyjafjallaMonster{
    public static final String ID = "eyjafjalla:CXXSS";
    private static final String MID_PATH = "CXXSS/enemy_1350_mgcshp_2";
    private static final MonsterStrings monsterStrings;
    private static final EnemyType TYPE = EnemyType.ELITE;
    private static final String ATTACK_NAME = "Attack";
    private static final String IDLE_NAME = "Idle";
    private static final String DIE_NAME = "Die";
    AbstractCard burn;

    public boolean attackStart;
    boolean specialStop = false;

    int attack;
    int strength = 4;
    float waitTime = 0.45F;

    public void setFastMode(){
        state.setTimeScale(1);
        this.waitTime = 0.45F;
    }

    public CXXSS(float x,float y,boolean attackStart){
        super(monsterStrings.NAME,ID,TYPE,96,240F,230F,x,y);
        this.attackStart = attackStart;
        setSpine(MID_PATH,1.6F);
        setFastMode();
        this.state.setAnimation(0,IDLE_NAME,true);

        if(AbstractDungeon.ascensionLevel>=8){
            setHp(90);
        }
        else {
            setHp(80);
        }
        if(AbstractDungeon.ascensionLevel>=3){
            attack = 16;
        }
        else {
            attack = 12;
        }
        if(AbstractDungeon.ascensionLevel>=18){
            strength = 4;
        }
        else {
            strength = 3;
        }
        burn = new Burn_Eyjafjalla();
        burn.upgrade();
        this.damage.add(new DamageInfo(this,this.attack, DamageInfo.DamageType.NORMAL));
    }

    @Override
    public void usePreBattleAction() {
        addToBot(new ApplyPowerAction(this,this,new GiveRedCloudPower(this,1),1));
        super.usePreBattleAction();
    }

    @Override
    protected void getMove(int i) {
        if(attackStart){
            this.setMove((byte) 1,Intent.ATTACK_DEBUFF,this.damage.get(0).base);
        }
        else {
            this.setMove((byte) 2,Intent.BUFF);
        }
        attackStart = !attackStart;
    }

    @Override
    public void takeTurn() {
        setFastMode();
        switch (this.nextMove){
            case 1:{
                addToBot(new ChangeStateAction(this,"ATTACK"));
                addToBot(new WaitAction(this.waitTime));
                addToBot(new DamageAction(AbstractDungeon.player,this.damage.get(0), AbstractGameAction.AttackEffect.SLASH_HEAVY));
                addToBot(new MakeTempCardInDiscardAction(burn,1));
                break;
            }
            case 2:{
                addToBot(new ApplyPowerAction(this,this,new StrengthPower(this,strength),strength));
                if(!specialStop){
                    specialStop = true;
                    addToBot(new ApplyStasisAction(this));
                }
                break;
            }
        }

        addToBot(new RollMoveAction(this));
    }

    @Override
    public void changeState(String stateName) {
        switch (stateName){
            case "ATTACK":{
                this.state.setAnimation(0,ATTACK_NAME,false);
                this.state.addAnimation(0,IDLE_NAME,true,0F);
                break;
            }
            default:
                break;
        }
    }

    @Override
    public void die() {
        this.state.setTimeScale(1F);
        state.setAnimation(0,DIE_NAME,false);
        super.die();

    }

    static {
        monsterStrings = CardCrawlGame.languagePack.getMonsterStrings(ID);
    }
}
